#include "sleeplock.h"


void initsleeplock(struct sleeplock * lk, char * name) {
  pthread_mutex_init(&lk->locked, 0);
  lk->name = name;
  lk->is_locked = 0;
}


void acquiresleep(struct sleeplock * lk) {
  pthread_mutex_lock(&lk->locked);
  lk->is_locked = 1;
}
void releasesleep(struct sleeplock * lk){
  lk->is_locked = 0;
  pthread_mutex_unlock(&lk->locked);
}

int holdingsleep(struct sleeplock * lk){
  return lk->is_locked;
}


void destroysleep(struct sleeplock * lk){
  pthread_mutex_destroy(&lk->locked);
  lk->name = 0;
  lk->is_locked = 0;
}
